package com.example.photography.adapter.community;

import android.content.Context;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.Appoint_OrderBean;
import com.example.photography.bean.UrlBean;
import com.example.photography.ui.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Com_AppointAdapter extends MyBaseAdapter {

    private List<UrlBean> urlBeans;
    private Item_ComProductAdapter item_comProductAdapter;

    public Com_AppointAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_com_appoint, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //装载数据
        Appoint_OrderBean appoint_orderBean = (Appoint_OrderBean) list.get(position);
        //头像
        Glide.with(mContext)
                .load(appoint_orderBean.getHead_url())
                .thumbnail(Glide.with(mContext).load(R.drawable.loading))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(viewHolder.ivHead);
        //昵称
        viewHolder.tvName.setText(appoint_orderBean.getName());
        viewHolder.tvIdentify.setText(appoint_orderBean.getIdentity() == 0 ? "模特" : "模特 摄影师");
        viewHolder.tvType.setText(appoint_orderBean.getType() == 0 ? "约摄影师" : "约模特");
        viewHolder.tvChargeType.setText(appoint_orderBean.getCharge_type() != null ? "希望互免" : "费用协商");
        viewHolder.tvSite.setText(appoint_orderBean.getSite());
        viewHolder.tvDemand.setText(appoint_orderBean.getDemand());
        viewHolder.tvDate.setText(appoint_orderBean.getDate());
        urlBeans = JSONObject.parseArray(appoint_orderBean.getU_product(), UrlBean.class);
        item_comProductAdapter = new Item_ComProductAdapter(urlBeans, mContext);
        viewHolder.gvProduct.setAdapter(item_comProductAdapter);
        // TODO: 2021/5/4 收到约拍数目和阅读量待实现
        int a = position % 5;
        switch (a) {
            case 0:
                viewHolder.rlTitle.setBackgroundResource(R.drawable.comment_blue);
                break;
            case 1:
                viewHolder.rlTitle.setBackgroundResource(R.drawable.comment_orange);
                break;
            case 2:
                viewHolder.rlTitle.setBackgroundResource(R.drawable.comment_gray);
                break;
            case 3:
                viewHolder.rlTitle.setBackgroundResource(R.drawable.comment_pink);
                break;
            case 4:
                viewHolder.rlTitle.setBackgroundResource(R.drawable.comment_yellow);
                break;
        }
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.iv_head)
        CircleImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_identify)
        TextView tvIdentify;
        @BindView(R.id.tv_focus)
        TextView tvFocus;
        @BindView(R.id.rl_title)
        RelativeLayout rlTitle;
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_charge_type)
        TextView tvChargeType;
        @BindView(R.id.tv_site)
        TextView tvSite;
        @BindView(R.id.tv_demand)
        TextView tvDemand;
        @BindView(R.id.gv_product)
        GridView gvProduct;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_appointnum)
        TextView tvAppointnum;
        @BindView(R.id.tv_pageview)
        TextView tvPageview;
        @BindView(R.id.ll_product)
        LinearLayout llProduct;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);

        }
    }
}
